//
//  BaseViewController.m
//  掌上宏力
//
//  Created by admin on 2017/4/26.
//  Copyright © 2017年 admin. All rights reserved.
//

#import "BaseViewController.h"
#import "LoginController.h"

#import "Reachability.h"

@interface BaseViewController ()
@property (nonatomic,strong) Reachability *reachability;

@end

@implementation BaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = Main_BGCOLOR;
    self.navigationController.navigationBar.translucent = NO;
    [self checkReachability];
}


- (void)checkReachability
{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reachabilityChanged:) name:kReachabilityChangedNotification object:nil];
    self.reachability = [Reachability reachabilityForInternetConnection];
    [self.reachability startNotifier];
    [self updateInterfaceWithReachability:self.reachability];
}

/*!
 * Called by Reachability whenever status changes.
 */
- (void) reachabilityChanged:(NSNotification *)note
{
    Reachability* curReach = [note object];
    NSParameterAssert([curReach isKindOfClass:[Reachability class]]);
    [self updateInterfaceWithReachability:curReach];
}

- (void)updateInterfaceWithReachability:(Reachability *)reachability
{
    //没有联网
    if (reachability.currentReachabilityStatus == NotReachable) {
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"没有网络，请稍后再试" preferredStyle:UIAlertControllerStyleAlert];
        [self presentViewController:alert animated:YES completion:nil];
        [self performSelector:@selector(dismissAlertView) withObject:nil afterDelay:1.5];
    }
}
-(void)dismissAlertView{
    [self dismissViewControllerAnimated:YES completion:nil];
    [self presentViewController:[LoginController new] animated:YES completion:nil];
}

//状态栏颜色
-(UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleLightContent;
}

-(void)viewWillDisappear:(BOOL)animated{
    [SVProgressHUD dismiss];
}
//界面跳转
-(void)pushViewControllerTo:(UIViewController *)vc {
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
    
}

-(void)viewWillAppear:(BOOL)animated{
    self.navigationController.navigationBar.translucent = NO;//default NO
    self.automaticallyAdjustsScrollViewInsets = YES; //default YES
}


@end
